import { ajax } from './ajax.js';

let txtEcho = document.getElementById('txtEcho');
let btnEcho = document.getElementById('btnEcho');
let divEcho = document.getElementById('divEcho');

btnEcho.addEventListener('click', () => {
  ajax.send('/', { echo: txtEcho.value }, 'GET', (data) => {
    console.log('应答结果：', data);
    divEcho.innerHTML = data.message;
  });
});

// 拼音的部分

let txtPinyin = document.getElementById('txtPinyin');
let btnPinyin = document.getElementById('btnPinyin');
let divPinyin = document.getElementById('divPinyin');

btnPinyin.addEventListener('click', () => {
  ajax.send(
    '/api/pinyin',
    {
      info: txtPinyin.value,
    },
    'POST',
    (data) => {
      divPinyin.innerHTML = data.message;
    }
  );
});
